package com.qf.springboot.async;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.mail.SimpleMailMessage;
import org.springframework.mail.javamail.JavaMailSender;
import org.springframework.mail.javamail.MimeMessageHelper;
import org.springframework.scheduling.annotation.Async;
import org.springframework.stereotype.Component;

import javax.mail.MessagingException;
import javax.mail.internet.MimeMessage;

@Component
public class LikeSleep {


    @Autowired
    private JavaMailSender javaMailSender;

    @Value("${spring.mail.username}")
    private String from;

    @Async
    public void sleep() throws MessagingException {
        System.out.println(Thread.currentThread().getName());

        MimeMessage mimeMessage = javaMailSender.createMimeMessage();
        MimeMessageHelper mimeMessageHelper = new MimeMessageHelper(mimeMessage,true);
        mimeMessageHelper.addTo("402424668@qq.com");
        mimeMessageHelper.setSubject("测试SpringBoot");
        mimeMessageHelper.setText("text/html","<h1 style='color:red;'>嘿嘿嘿！</h1>");
        mimeMessageHelper.setFrom(from);

        javaMailSender.send(mimeMessage);
        System.out.println("睡醒了！！！！");
    }



}
